/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package de.swta;

import java.util.Iterator;
import org.apache.wicket.extensions.markup.html.repeater.util.SortParam;
import org.apache.wicket.extensions.markup.html.repeater.util.SortableDataProvider;
import org.apache.wicket.model.IModel;

/**
 *
 * @author Jan Korreck
 */
public class SortableCategoryProvider extends SortableDataProvider {


    public SortableCategoryProvider() {
        setSort("id", true);
    }

    public Iterator iterator(int first, int count) {
        SortParam sp = getSort();
        String property = sp.getProperty();
        boolean isAsc = sp.isAscending();

        return CategoryManager.getInstance().find(first, count, property, isAsc).iterator();
    }

    public int size() {
        return CategoryManager.getInstance().getSize();
    }

    public IModel model(Object cat) {
        return new DetacheableCategoryModel((Category) cat);
    }
}
